home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
a_utils
/
expanded.lha
/
expanded
/
hdr
/
Geom.h
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
39KB
|
1,434 lines
//
// Linear-Affine-Projective Geometry Package
//
// Geom.h
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Implementation of the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#ifndef Geom_h
#define Geom_h
#include <stream.h>
#include <string.h>
#include "Lap1.h"
#include "Object.h"
#include "Matrix.h"
// ***********************************************************************
//
// IMPORTANT NOTES:
//
// Inheritance:
//
// The use of inheritance in this class hierarchy is unusual, but
// was dictated by the goals that were set for the implementation, and
// the desire to keep things as simple as possible. The generic
// base classes (e.g. Map, Space, GeOb, Basis, MultiMap, SubSet)
// serve as the main classes in the system. While these base classes
// also have child classes, child classes are really only included to
// provide static types and automatic typecasting. Child classes are
// NOT being used to factor out implementation details that are unique
// to a particular type of class. In this system, the generic base
// classes implements most of the functionality, and the child
// classes just implement a few things like constructors and assignment.
// This approach was intended to give the system a measure of dynamic
// typing, while trying to keep the implementation as simple as possible.
// For example, an object from the generic Map class can hold
// any type of map (Affine, Linear, or Projective), and since the generic
// base class Map implements all the functions for the various types
// of maps it can hold, no downcasting is necessary.
// There are a few instances where specific functionality has been
// factored into the child classes. The GeOb's MapTo() function and the
// Space's SetSpace() function are two examples. In these instances, the
// functions are implemented as virtual functions, and the implementation
// in the generic base classes just does downcasting. This is one
// way in which some amount of the implementation details can be
// moved down into the child classes. However, given the goals that
// were set down for the implementation, it seems that it would be
// very difficult to make a system using C++ where the base classes
// didn't need to know something about their child classes.
// For more discussion of this issue, consult the thesis writeup.
//
// Friend classes:
//
// The user will note that friend classes are used liberally in
// this implementation. This arises out of the desire to prevent
// the user from having access to the functions that the implementing
// classes use to work together. The only real way to do this in C++
// is to make the classes friends of each other. However, friend
// classes still are designed to only interact using member functions
// (albeit private functions), and not by accessing data directly.
// This policy is not enforced by the compiler, but by programming
// convention.
//
// Compiler:
//
// This system has compiled and run successfully using CFRONT 1.2.
// It was also designed to work with g++, specifically version 1.37.1
// (which is what was on the CSE department Sun workstations during
// development). Some apparent g++ bugs (such as inheritance of
// assignment) have workarounds in the code. However, there continue
// to be problems with g++, particularly with abnormal destructor calls
// that show up with matrices (size > 4) that need to use the heap.
// Thus, the use of g++ 1.37.1 IS NOT RECOMMENDED, except to do debugging
// using gdb, and then only with small dimension matrices. For more
// discussion, see the thesis writeup.
//
// Efficiency:
//
// This implementation is really only a "first cut". The goal for the
// project was to build a correct implementation of the ADT and do it as
// simply as possible. Unfortunately, efficiency considerations typically
// took a back seat, and the next logical step in the process would be to
// find the bottlenecks in the implementation and work to improve their
// efficiency. There are undoubtedly LOTS of ways to speed up the
// system. In fact, some aspects of this implementation are embarassingly
// inefficient.
// However, some relatively simple steps can be taken to improve
// performance. For example, the implementing classes use many of the
// the same functions that are provided to the user. While this made
// the system easy to implement, it takes a big toll on performance, since
// the user interface functions do lots of safety checks and necessary
// type conversions, and return their results (functional semantics).
// While functional semantics is a nice property, it does result in lots
// of object copying. The preferable alternative would be to provide the
// implementing classes with special functions that do not include these
// features. For example, instead of using the functions
//
// Boolean GeOb::CanMapTo(GeObType t);
// GeOb GeOb::MapTo(GeObType t);
// GeOb Map::operator()(GeOb& v);
// Boolean SubSet::IsIn(GeOb& g);
//
// in the implementation to check and change GeOb representations, there
// should be functions available ONLY to the implementing classes that
// reduce copying and remove some safety checks, e.g.
//
// Boolean GeOb::MapTo(GeObType t, GeOb* out);
// GeOb Map::Apply(GeOb& v, GeOb* out);
// Boolean SubSet::IsInNoCast(GeOb& g);
//
// The first function would fill in the target GeOb with the mapped
// GeOb if it could, or would return FALSE if the mapping could not be
// performed. The second would apply a map, but would assume the
// argument is of the correct type. Perhaps it might also assume
// that the argument is in the domain (i.e. it would require the
// caller to check CanMap() first). The third function would also
// assume its argument is of the correct type. Using functions like
// these in the implementation layer can go a long way to improving
// efficiency. Of course, it means more functions to implement and
// fewer safeguards.
//
// ***********************************************************************
class Space: public Object
{
protected:
// Object Data:
SpaceType type;
SpaceType holds;
SpaceInfo *info;
// Functions used only by Space & derived classes. VSpace must be made
// a friend under g++ (not CFRONT 1.2) to access the functions tagged
// by **:
friend class VSpace;
void MergeSets(Space& set2); // **
void SetSpaceSet(SRel s, Space& s); // **
void SetDual(Space& s); // **
char* BuildTagName(char* tag, Space& s);
void DestroyTagName(char* buf);
void CopyDebugName(char* buf);
void BuildEuclidean(Boolean eflag);
void Broadcast(SRel s, Space& ins);
void SetStdLMap(Map& m);
void SetStdAMap(SRel s, Map& m);
void SetStdPMap(Map& m);
Boolean HaveLink(Space& s1, SRel r1,
Space& s2, SRel r2, Boolean* have_error);
void LinkLT(void);
void LinkAP(AffineMap& m); // 1
void LinkLA(AffineMap& m); // 2
void LinkLP(ProjectiveMap& m); // 3
void LinkLAHaveLP(AffineMap& m); // 4
void LinkAPHaveLP(AffineMap& m); // 5
void LinkLAHaveAP(AffineMap& m); // 6
void LinkAPHaveLA(AffineMap& m); // 7
void LinkLPHaveLA(ProjectiveMap& m); // 8
void LinkLPHaveAP(ProjectiveMap& m); // 9
void data_out(ostream& c, int indent, char* name);
void heavy_data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class. Cross ratio functions also need to
// be friends:
friend class Basis;
friend class Simplex;
friend class Frame;
friend class VBasis;
friend class HFrame;
friend class GeOb;
friend class Vector;
friend class AVector;
friend class VectorEC;
friend class APoint;
friend class AVectorEC;
friend class PPoint;
friend class Map;
friend class AffineMap;
friend class ProjectiveMap;
friend class MultiMap;
friend class MLM;
friend class MAM;
friend class SubSet;
friend class ASubSet;
friend class PSubSet;
friend PPoint CrossRatio(AugScalar v, GeObList& g);
friend AugScalar CrossRatioCalc(GeObList& g);
int MatrixSize(void);
int StartSlot(int n);
Matrix& HoistTangent(void);
AffineMap& AffineMapToRef(SRel s);
ProjectiveMap& ProjectiveMapToRef(SRel s);
LinearMap& LinearMapToRef(SRel s);
public:
// Creation:
Space(void);
Space(Space& v);
// Interrogation functions:
int Dim(void);
char* Name(char *buf);
SpaceType Holds(void) {return holds;}
Basis StdBasis(void);
SRel SpaceRelation(Space& s);
SRel ThisSpaceIs(void);
Boolean HasSpace(SRel s);
Space GetSpace(SRel s);
SubSet FullSet(void);
GeObType NativeType(void);
AffineMap AffineMapTo(SRel s);
ProjectiveMap ProjectiveMapTo(SRel s);
LinearMap LinearMapTo(SRel s);
VSpace Dual(void);
Simplex StdSimplex(void);
Boolean IsEuclidean(void);
MLM InnerProduct(void);
MLM CrossProduct(void);
GeObList PtsAtInfinity(void);
PSubSet FullProjSet(void);
ASubSet StdAffineSubset(void);
// Space set building:
virtual Space SetSpace(Space& s, Map& m);
// Comparison operators:
Boolean operator==(Space& s) {return (info == s.info);}
Boolean operator!=(Space& s) {return (info != s.info);}
// Cartesian Product Operations:
Space operator[](int n);
int CPSpaceSize(void);
// Assignment:
Space& operator=(Space& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
void heavy_debug_out(ostream& c, int indent);
};
// ***********************************************************************
class VSpace: public Space
{
private:
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Space;
VSpace(SRel s, Space& ins);
public:
// Creation:
VSpace(void) : () {type = VEC_SPACE;}
VSpace(VSpace& v) : (v) {type = VEC_SPACE;}
VSpace(char *namein, int n, Boolean eflag);
VSpace(char *namein, Boolean eflag, ASpace& a, PSpace& p);
VSpace(char *namein, Boolean eflag, Space& a);
VSpace(char *namein, SpaceList& t, Boolean eflag);
VSpace(Space& s);
// Space set building:
Space SetSpace(Space& s, Map& m);
// Assignment:
VSpace& operator=(VSpace& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class ASpace: public Space
{
private:
Matrix BuildHoist(int n);
public:
// Creation:
ASpace(void) : () {type = AFF_SPACE;}
ASpace(ASpace& s) : (s) {type = AFF_SPACE;}
ASpace(char *namein, int n, Boolean eflag);
ASpace(char *namein, Boolean eflag, VSpace& v, PSpace& p);
ASpace(char *namein, Boolean eflag, Space& ins);
ASpace(char *namein, SpaceList& t, Boolean eflag);
ASpace(Space& s);
// Space set building:
Space SetSpace(Space& s, Map& m);
// Assignment:
ASpace& operator=(ASpace& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class PSpace: public Space
{
public:
// Creation:
PSpace(void) : () {type = PROJ_SPACE;}
PSpace(PSpace& v) : (v) {type = PROJ_SPACE;}
PSpace(char *namein, int n);
PSpace(char *namein, VSpace& v, ASpace& a);
PSpace(char *namein, Space& v);
PSpace(Space& s);
// Space set building:
Space SetSpace(Space& s, Map& m);
// Assignment:
PSpace& operator=(PSpace& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class SubSet: public Object
{
protected:
// Object Data:
SubSetType type;
SubSetType holds;
SubSetInfo *info;
// Used by only by SubSet & derived classes:
SubSet(SubSetInfo* ts);
char* BuildTagName(char* tag, SubSet& s);
char* BuildTagName(char* tag, Space& s);
void DestroyTagName(char* buf);
void CopyDebugName(char* buf);
Boolean ConvertList(GeObList& v, GeObType targ,
Space& destspace, Matrix* temp);
Matrix GSO(Matrix& have, Matrix& try, int start,
int dim, Boolean* error);
Boolean Orth(Matrix* have, int count, Matrix& try, int tryrow);
Matrix& AugBasis(void);
int IsOffset(void);
Scalar Offset(void);
void data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Map;
friend class LinearMap;
friend class AffineMap;
friend class ProjectiveMap;
Matrix& FromFull(void);
Matrix& ToFull(void);
GeOb Normalize(GeOb&);
Scalar NormVal(SubSet& targ);
public:
// Constructors:
SubSet(void);
SubSet(SubSet& s);
// Interrogation functions:
char* Name(char *buf);
int Dim(void);
SubSetType Holds(void) {return (holds);}
Space EmbeddingSpace(void);
GeObType Accepts(void);
Boolean IsIn(GeOb& g);
Boolean IsSubset(SubSet& s);
Boolean IsFullSpace(void);
Boolean HasRemovedPoints(void);
GeObList AtInfinity(void);
VSubSet TangentSub(void);
// Assignment:
SubSet& operator=(SubSet& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class VSubSet: public SubSet
{
private:
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class VSpace;
VSubSet(VSpace& s); // Not intended for casting spaces!
public:
// Creation:
VSubSet(void) : () {type = LINEAR_SUBSET;}
VSubSet(VSubSet& s) : (s) {type = LINEAR_SUBSET;}
VSubSet(SubSet& s);
VSubSet(char *namein, VSpace& s, GeObList& v);
// Assignment:
VSubSet& operator=(VSubSet& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class ASubSet: public SubSet
{
private:
// Used by ASubSet:
ASubSet(ASubSet& a, ProjectiveMap&m);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class AffineMap;
friend class ASpace;
ASubSet(Space& s); // Not intended for casting spaces!
public:
// Creation:
ASubSet(void) : () {type = AFFINE_SUBSET;}
ASubSet(ASubSet& s) : (s) {type = AFFINE_SUBSET;}
ASubSet(SubSet& s);
ASubSet(char *namein, Space& s, GeObList& v);
ASubSet(char *namein, PSpace& s, GeOb& v, GeObList& inf);
// Assignment:
ASubSet& operator=(ASubSet& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class PSubSet: public SubSet
{
private:
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class VSpace;
friend class PSpace;
PSubSet(Space& s); // Not intended for casting spaces!
public:
// Creation:
PSubSet(void) : () {type = PROJECTIVE_SUBSET;}
PSubSet(PSubSet& s) : (s) {type = PROJECTIVE_SUBSET;}
PSubSet(SubSet& s);
PSubSet(char *namein, Space& s, GeObList& v);
PSubSet(char *namein, Space& s, GeObList& bp, GeObList& v);
// Assignment:
PSubSet& operator=(PSubSet& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class Basis: public Object
{
protected:
// Object Data:
BasisType type; // What type of basis it is.
BasisType holds; // Type of current contents.
Space s; // The containing space.
char name[MAX_NAMESIZE]; // Name of Basis.
Matrix tostdb; // Rep. of basis rel. to StdBasis.
Matrix fromstdb; // Rep. of StdBasis rel. to basis.
// Used only by Basis class:
Basis(BasisType b, Space& s, char *name, Matrix& m);
void data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Vector;
friend class AVector;
friend class APoint;
friend class PPoint;
friend class LinearMap;
friend class AffineMap;
friend class ProjectiveMap;
friend class VSpace;
friend class ASpace;
friend class PSpace;
Basis(BasisType b, Space& ins, int size);
Matrix& Tostdb(void) {return (tostdb);}
Matrix& Fromstdb(void) {return (fromstdb);}
public:
// Constructors:
Basis(void) {type = ANY_BASIS; holds = NULL_BASIS;}
Basis(Basis& b);
// Interrogation functions:
Space SpaceOf(void) {return (s);}
BasisType Holds(void) {return (holds);}
char* Name(char *buf) {return (strcpy(buf, name));}
GeOb operator[](int n);
ScalarList operator()(GeOb& v);
VBasis Dual(void);
// Assignment:
Basis& operator=(Basis& b);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class Simplex: public Basis
{
public:
// Constructors:
Simplex(void) : () {type = SIMPLEX;}
Simplex(Simplex& b) : (b) {type = SIMPLEX;}
Simplex(char* namein, GeOb& t);
Simplex(char* namein, ASpace& ins, GeObList& t);
Simplex(Basis& f);
// Assignment:
Simplex& operator=(Simplex& b);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class Frame: public Basis
{
public:
// Constructors:
Frame(void) : () {type = FRAME;}
Frame(Frame& f) : (f) {type = FRAME;}
Frame(char* namein, ASpace& ins, GeObList& t);
Frame(Basis& f);
Frame(Simplex& b, int n);
// Assignment:
Frame& operator=(Frame& f);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class VBasis: public Basis
{
public:
// Constructors:
VBasis(void) : () {type = VBASIS;}
VBasis(VBasis& v) : (v) {type = VBASIS;}
VBasis(char* namein, GeOb& t);
VBasis(char* name, VSpace& ins, GeObList& t);
VBasis(Basis& f);
// Assignment:
VBasis& operator=(VBasis& b);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class HFrame: public Basis
{
public:
// Constructors:
HFrame(void) : () {type = HFRAME;}
HFrame(HFrame& h) : (h) {type = HFRAME;}
HFrame(char* namein, PSpace& ins, GeObList& t);
HFrame(Basis& f);
// Assignment:
HFrame& operator=(HFrame& h);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class GeOb: public Object
{
protected:
// Object Data:
GeObType type; // The type of geometric object
GeObType holds; // The type currently held
Space s; // The containing space.
Matrix m; // Coords relative to s.stdbasis
// Used only by GeOb
void data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Basis;
friend class Simplex;
friend class Frame;
friend class VBasis;
friend class HFrame;
friend class Map;
friend class ProjectiveMap;
friend class MultiMap;
friend class MLM;
friend class MAM;
friend class SubSet;
// Friend declarations required by g++ (not CFRONT 1.2):
friend class Vector;
friend class AVector;
friend class VectorEC;
friend class AVectorEC;
friend class APoint;
friend class PPoint;
GeOb(GeObType g, Space& ins, Matrix& inm);
Matrix& MatrixRep(void) {return (m);}
public:
// Constructors:
GeOb(void) {type = ANY_GEOB; holds = NULL_GEOB;}
GeOb(GeOb& g);
GeOb(MultiMap& mp);
GeOb(Map& mp);
GeOb(Scalar v);
// Interrogation functions:
Space SpaceOf(void) {return (s);}
GeObType Holds(void) {return (holds);}
virtual Boolean CanMapTo(GeObType t);
Boolean IsZeroVector(void);
GeOb operator[](int n);
GeObList TupleElements(void);
// Operations:
friend GeOb operator-(GeOb& th);
friend GeOb operator+(GeOb& th, GeOb& g);
friend GeOb operator-(GeOb& th, GeOb& g);
friend GeOb operator*(GeOb& th, GeOb& g);
friend GeOb operator/(GeOb& th, GeOb& g);
Scalar Apply(GeOb& a);
GeOb Dual(void);
virtual GeOb MapTo(GeObType t);
GeOb SetTupleElement(int n, GeOb& g);
// Cross ratio functions are friends:
friend PPoint CrossRatio(AugScalar v, GeObList& g);
friend AugScalar CrossRatioCalc(GeObList& g);
// Manual typecasting:
Scalar ToScalar(void);
// Assignment:
GeOb& operator=(GeOb& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class Vector: public GeOb
{
public:
Vector(void) : () {type = VECTOR;}
Vector(Vector& v) : (v) {type = VECTOR;}
Vector(GeOb& a) : (a.MapTo(VECTOR)) {type = VECTOR;}
Vector(MultiMap& mp) {type = VECTOR; *this = Vector(GeOb(mp));}
Vector(Map& mp) {type = VECTOR; *this = Vector(GeOb(mp));}
Vector(Scalar s) : (s) {type = VECTOR;}
Vector(VBasis& b, ScalarList& a);
Vector(VSpace& s, GeObList& s);
Vector(VSpace& s, GeOb& v1, GeOb& v2);
Vector(VSpace& s, GeOb& v1, GeOb& v2, GeOb& v3);
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
Vector& operator=(Vector& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class AVector: public GeOb
{
public:
// Constructors:
AVector(void) : () {type = AFF_VECTOR;}
AVector(AVector& v) : (v) {type = AFF_VECTOR;}
AVector(GeOb& a) : (a.MapTo(AFF_VECTOR)) {type = AFF_VECTOR;}
AVector(MultiMap& mp) {type = AFF_VECTOR; *this = AVector(GeOb(mp));}
AVector(Map& mp) {type = AFF_VECTOR; *this = AVector(GeOb(mp));}
AVector(Basis& b, ScalarList& a);
AVector(VSpace& s, GeObList& s);
AVector(VSpace& s, GeOb& v1, GeOb& v2);
AVector(VSpace& s, GeOb& v1, GeOb& v2, GeOb& v3);
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
AVector& operator=(AVector& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class VectorEC: public GeOb
{
public:
// Constructors:
VectorEC(void) : () {type = VEC_EC;}
VectorEC(VectorEC& v) : (v) {type = VEC_EC;}
VectorEC(GeOb& a) : (a.MapTo(VEC_EC)) {type = VEC_EC;}
VectorEC(MultiMap& mp) {type = VEC_EC; *this = VectorEC(GeOb(mp));}
VectorEC(Map& mp) {type = VEC_EC; *this = VectorEC(GeOb(mp));}
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
VectorEC& operator=(VectorEC& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class AVectorEC: public GeOb
{
public:
// Constructors:
AVectorEC(void) : () {type = AFF_VEC_EC;}
AVectorEC(AVectorEC& v) : (v) {type = AFF_VEC_EC;}
AVectorEC(GeOb& a) : (a.MapTo(AFF_VEC_EC)) {type = AFF_VEC_EC;}
AVectorEC(MultiMap& mp) {type=AFF_VEC_EC; *this = AVectorEC(GeOb(mp));}
AVectorEC(Map& mp) {type = AFF_VEC_EC; *this = AVectorEC(GeOb(mp));}
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
AVectorEC& operator=(AVectorEC& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class APoint: public GeOb
{
public:
// Constructors:
APoint(void) : () {type = AFF_POINT;}
APoint(APoint& p) : (p) {type = AFF_POINT;}
APoint(GeOb& a) : (a.MapTo(AFF_POINT)) {type = AFF_POINT;}
APoint(Basis& s, ScalarList& a);
APoint(ASpace& s, GeObList& s);
APoint(ASpace& s, GeOb& v1, GeOb& v2);
APoint(ASpace& s, GeOb& v1, GeOb& v2, GeOb& v3);
APoint(MultiMap& mp) {type = AFF_POINT; *this = APoint(GeOb(mp));}
APoint(Map& mp) {type = AFF_POINT; *this = APoint(GeOb(mp));}
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
APoint& operator=(APoint& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class PPoint: public GeOb
{
public:
// Constructors:
PPoint(void) : () {type = PROJ_POINT;}
PPoint(PPoint& v) : (v) {type = PROJ_POINT;}
PPoint(GeOb& a) : (a.MapTo(PROJ_POINT)) {type = PROJ_POINT;}
PPoint(MultiMap& mp) {type = PROJ_POINT; *this = PPoint(GeOb(mp));}
PPoint(Map& mp) {type = PROJ_POINT; *this = PPoint(GeOb(mp));}
PPoint(HFrame& s, ScalarList& a);
// Mapping:
virtual Boolean CanMapTo(GeObType t);
virtual GeOb MapTo(GeObType t);
// Assignment:
PPoint& operator=(PPoint& g);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class Map: public Object
{
protected:
// Object Data:
MapType type;
MapType holds;
Boolean invertible;
SubSet range;
SubSet domain;
Matrix t;
Matrix invt;
GeObType domtype;
GeObType rettype;
Boolean hasAL;
Boolean isDefault;
// Functions used by Map & derived classes:
Map(MapType t, Boolean i, SubSet& r,
SubSet& d, Matrix& tm, Matrix& it, Boolean isdf,
Boolean hal, GeObType dt, GeObType rt);
Boolean ConvertList(GeObList& v, GeObType targ,
SubSet& dest, Matrix* hold);
GeOb ApplyAL(GeOb& v);
void data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
// Used also by friend classes:
friend class GeOb;
friend class MultiMap;
friend class ASubSet;
Matrix& MatrixRep(void) {return (t);}
GeObType DomainType(void) {return (domtype);}
GeObType ReturnType(void) {return (rettype);}
public:
// Creation:
Map(void) {type = ANY_MAP; holds = NULL_MAP;}
Map(Map& m);
Map(MultiMap& m);
Map(GeOb& g);
// Interrogation functions:
SubSet Range(void) {return (range);}
SubSet Domain(void) {return (domain);}
MapType Holds(void) {return (holds);}
Boolean Invertible(void) {return (invertible);}
// Functions to apply maps:
GeOb operator()(GeOb& v);
// Functions that compose and invert maps:
Map Inv(void);
Map Compose(Map& m);
ProjectiveMap ComposeProj(Map& m);
// Functions to obtain induced maps:
ProjectiveMap InducedProjective(void);
LinearMap InducedLinear(void);
LinearMap Trans(void);
LinearMap AssocLinear(void);
Vector AssocDualVector(void);
// Assignment:
Map& operator=(Map& m);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class LinearMap: public Map
{
public:
// Creation:
LinearMap(void) : () {type = LIN_MAP;}
LinearMap(LinearMap& m) : (m) {type = LIN_MAP;}
LinearMap(Map& m);
LinearMap(MultiMap& m) {type = LIN_MAP; *this = LinearMap(Map(m));}
LinearMap(GeOb& g) {type = LIN_MAP; *this = LinearMap(Map(g));}
LinearMap(VBasis& b1, VBasis& b2);
LinearMap(VBasis& b, VSubSet& s, GeObList& v);
LinearMap(VSubSet& s, GeObList& v, VBasis& b);
LinearMap(VSubSet& s1, GeObList& v1, VSubSet& s2, GeObList& v2);
// Assignment:
LinearMap& operator=(LinearMap& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class AffineMap: public Map
{
private:
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Space;
friend class VSpace;
friend class ASpace;
friend class PSpace;
AffineMap(Space& s1, Space& s2);
AffineMap(ProjectiveMap& lpm, AffineMap& lam); //link 4,8
AffineMap(AffineMap& apm, ProjectiveMap& lpm); //link 5,9
public:
// Creation:
AffineMap(void) : () {type = AFF_MAP;}
AffineMap(AffineMap& m) : (m) {type = AFF_MAP;}
AffineMap(Map& m);
AffineMap(MultiMap& m) {type = AFF_MAP; *this = AffineMap(Map(m));}
AffineMap(Basis& b1, Basis& b2);
AffineMap(Simplex& b, SubSet& s, GeObList& v);
AffineMap(ASubSet& s, GeObList& v, Simplex& b);
AffineMap(ASubSet& s1, GeObList& v1, SubSet& s2, GeObList& v2);
// Assignment:
AffineMap& operator=(AffineMap& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class ProjectiveMap: public Map
{
private:
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Space;
friend class VSpace;
friend class ASpace;
friend class PSpace;
ProjectiveMap(Space& s1, Space& s2);
Boolean ScaleRows(Matrix* mat, Matrix& unit_pt);
Boolean ConvertListUnit(GeObList& v, GeObType trg, SubSet& d,
Matrix* hold, Matrix* unit);
ProjectiveMap(VSpace& L, AffineMap& lpm, PSpace& P); //link 6,7
public:
// Creation:
ProjectiveMap(void) : () {type = PROJ_MAP;}
ProjectiveMap(ProjectiveMap& m) : (m) {type = PROJ_MAP;}
ProjectiveMap(Map& m);
ProjectiveMap(HFrame& b1, HFrame& b2);
ProjectiveMap(HFrame& b, PSubSet& s, GeObList& v);
ProjectiveMap(PSubSet& s, GeObList& v, HFrame& b);
ProjectiveMap(PSubSet& s1, GeObList& v1, PSubSet& s2, GeObList& v2);
// Assignment:
ProjectiveMap& operator=(ProjectiveMap& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
//
// This class is used by MultiMaps for holding onto data. It is ONLY
// intended to be used internally by the system. It is included here
// because the subsequent MultiMap class declaration requires it.
// There is currently a limit of 10 symmetry sets. Make this a global
// variable instead of a static class variable because it is needed by
// other classes too:
const int SYM_MAX = 10;
class MMData: public Object
{
private:
Matrix t; // Control net (Bezier or Hypercube);
int numsym; // Number of symmetry sets
int deg[SYM_MAX]; // Degree of each symmetry set
int dim[SYM_MAX]; // Dimension of each symmetry set
Boolean isAntisym; // True if map is antisymmetric
public:
// Creation:
MMData(void) {numsym = 0;}
MMData(MMData& m);
// Member functions:
Matrix& Net(void) {return (t);}
int& Numsym(void) {return (numsym);}
Boolean& IsAntisym(void) {return (isAntisym);}
// Caution! No bounds checking in following functions:
int& Deg(int index) {return (deg[index]);}
int& Dim(int index) {return (dim[index]);}
int NetSize(void);
int WhichSet(int argnum);
void RemoveSymSet(int inset);
// Assignment:
MMData& operator=(MMData& m);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class MultiMap: public Object
{
protected:
// Object Data:
MultiType type;
MultiType holds;
Boolean fulleval;
Space range;
Space domain;
MMData data;
GeObType domtype;
GeObType rettype;
// Functions used by MultiMaps and derived classes:
void Eval(int argnum, ScalarList& coords, MMData* rdat);
void PtEval(ScalarList& c, MITuple* t, int el, MMData* rdat);
void PtEvalAnti(ScalarList& c, MITuple* t, MMData* rdat,
Matrix* newmat, Scalar oesign);
void BasisArg(MITuple& tup, Space& s, GeObList* gl);
void PartialEval(GeObList& t, SpaceList* nd, MultiMap* ret);
void data_out(ostream& c, int indent, char* name);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class GeOb;
friend class Map;
GeObType DomainType(void) {return (domtype);}
GeObType RetType(void) {return (rettype);}
Boolean IsAntisym(void) {return (data.IsAntisym());}
// Caution! User must first make sure map is fully evaluated!
Matrix& FullEvalRep(void) {return data.Net();};
Matrix GetStdImage(int n);
public:
// Creation:
MultiMap(void) {type = ANY_MULTI; holds = NULL_MULTI;}
MultiMap(GeOb& s) {type = ANY_MULTI; *this = MultiMap(Map(s));}
MultiMap(MultiMap& v);
MultiMap(Map& s);
// Interrogation functions:
Space RangeSpace(void) {return (range);}
Space DomainSpace(void) {return (domain);}
Boolean FullyEvaluated(void) {return (fulleval);}
MultiType Holds(void) {return (holds);}
// Typecasting:
Scalar ToScalar(void) {return (GeOb(*this).ToScalar());}
// Functions to apply maps and do partial evaluation:
GeOb operator()(GeOb& t);
MultiMap operator()(GeObList& t);
MultiMap operator()(Space& newdom, GeObList& t);
// Assignment:
MultiMap& operator=(MultiMap& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class MLM: public MultiMap
{
private:
// Functions used by MLM:
void DotProduct(VSpace& sp);
Scalar DotResult(MITuple& tup);
Matrix CrossResult(MITuple& tup, Basis& stdbas);
void CrossProduct(VSpace& sp);
// Functions also used by friend classes. Though the compiler cannot
// enforce it, friend classes (by convention) do not access any other
// private members of this class:
friend class Space;
MLM(StdMaps mpt, VSpace& sp);
public:
// Creation:
MLM(void) : () {type = MULTI_LINEAR;}
MLM(MLM& m) : (m) {type = MULTI_LINEAR;}
MLM(MultiMap& m);
MLM(Map& s) {type = MULTI_LINEAR; *this = MLM(MultiMap(s));}
MLM(GeOb& s);
MLM(VSpace& s1, IntList& symmetry, BasisList& bases,
VSpace& s2, GeObList& vectors);
// Assignment:
MLM& operator=(MLM& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class MAM: public MultiMap
{
public:
// Creation:
MAM(void) : () {type = MULTI_AFFINE;}
MAM(MAM& m) : (m) {type = MULTI_AFFINE;}
MAM(MultiMap& m);
MAM(Map& m) {type = MULTI_AFFINE; *this = MAM(MultiMap(m));}
MAM(ASpace& s1, IntList& symmetry, BasisList& simplices,
Space& s2, GeObList& images);
// Assignment:
MAM& operator=(MAM& s);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
class AugScalar: public Object
{
protected:
// Object Data:
Boolean is_inf;
Matrix m;
// Functions used by cross ratio function:
friend PPoint CrossRatio(AugScalar v, GeObList& g);
Matrix& GetMatrix(void) {return m;}
public:
// Creation:
AugScalar(void);
AugScalar(AugScalar& a);
AugScalar(Scalar v);
AugScalar(Infnum n);
// Interrogation functions:
Scalar Value(void);
Boolean IsInfinity(void) {return is_inf;}
// Typecasting:
operator Scalar();
// Assignment:
AugScalar& operator=(AugScalar& a);
// To do debug printing:
void debug_out(ostream& c, int indent);
};
// ***********************************************************************
//
// Scalars can be converted to and from vectors in this special
// 1-dimensional space. Declare the existence of this space:
//
extern VSpace Reals;
// ***********************************************************************
//
// Null geometric objects are useful for doing partial evaluation
// of multimaps. Declare the existence of a standard null object:
//
extern GeOb NullGeOb;
#endif